package cn.xfdzx.android.apps.shop.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.VideoHeadListMoreAdapter;
import cn.xfdzx.android.apps.shop.bean.VideoAvatarListBeen;

/**
 * @autor: zf
 * @Description: 主播端查看在线人数列表弹窗
 * @Date: 2020/7/10 12:18
 */
public class ShowLookOnLiveDialog extends Dialog implements View.OnClickListener {

    private Context context;
    private ImageView iv_close;
    private RecyclerView rv_online_list;
    private VideoHeadListMoreAdapter adapter;
    private List<VideoAvatarListBeen> videoTopAvatarList = new ArrayList<>();//直播间顶部用户头像列表
    public ShowLookOnLiveDialog(@NonNull Context activity, List<VideoAvatarListBeen> videoTopAvatarList) {
        super(activity, R.style.CustomDialog_Translucent);
        this.context = activity;
        this.videoTopAvatarList = videoTopAvatarList;
        setCanceledOnTouchOutside(true); // 点击空白区域可以Dismiss对话框
        setCancelable(true); // 点击返回按键可以Dismiss对话框
        init();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        init();
    }

    public void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_showliveonline, null);
        setContentView(view);

        iv_close = findViewById(R.id.iv_close);
        rv_online_list = findViewById(R.id.rv_online_list);

        iv_close.setOnClickListener(this);

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 高度设置为屏幕的0.6
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        adapter = new VideoHeadListMoreAdapter(context,videoTopAvatarList);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
        rv_online_list.setLayoutManager(linearLayoutManager);
        rv_online_list.setAdapter(adapter);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_close:
                this.dismiss();
                break;
            default:
                this.dismiss();
                break;

        }
        this.dismiss();
    }
//    public void setChoseTypeListener(setChoseTypeListener listener){
//            this.choseTypeListener = listener;
//    }
//
//    public interface setChoseTypeListener {
//        void onChoseType(int type);
//    }
}
